package com.tmall.testgen.plugin.views.action;

import org.eclipse.jface.action.Action;

import com.tmall.testgen.client.commond.InfoReceiveListener;
import com.tmall.testgen.client.commond.SendCommondInstance;
import com.tmall.testgen.client.socket.SocketClient;
import com.tmall.testgen.plugin.Activator;
import com.tmall.testgen.server.socket.CommondEnum;

/**
 * 开始
 * 
 * @author star
 * 
 */
public class StartAction extends Action {
	private InfoReceiveListener listener;
	public static final String ID = "startAction";
	public StartAction(InfoReceiveListener listener) {
		super("开始",Action.AS_CHECK_BOX);
		setId(ID);
		setToolTipText("start test");
		setImageDescriptor(ImageManeger.getImageDescriptor(ImageManeger.USED_START));
		this.listener = listener;
	}

	
	public void run() {
		
		if(!SocketClient.getInstance().isStart())
			return;
		
		SendCommondInstance.getSendCommond().sendCommond(CommondEnum.BeginIntercept);
		changeChecked(isChecked());
		listener.actionChecked(this);
	}
	public void changeChecked(boolean checked){
		setEnabled(!checked);
		setChecked(checked);
		if(!checked){
			setImageDescriptor(ImageManeger.getImageDescriptor(ImageManeger.USED_START));
		}else{
			setImageDescriptor(ImageManeger.getImageDescriptor(ImageManeger.UN_USED_START));
		}
	}
}
